/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.gac.gacmod.visual;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.LinkedList;
import java.util.List;
import org.netbeans.api.visual.router.Router;
import org.netbeans.api.visual.widget.ConnectionWidget;
import org.netbeans.api.visual.widget.Widget;

/**
 *
 * @author Tomek
 */
public class RepeatEdgeRouter implements Router
{
    Point _start;
    Point _end;
    Widget _innerWidget;

    private static int margin = 10;

    public RepeatEdgeRouter( Widget innerWidget )
    {
        _innerWidget = innerWidget;
    }

    public List<Point> routeConnection(ConnectionWidget connectionWidget)
    {
        Rectangle widgetRect = _innerWidget.convertLocalToScene( _innerWidget.getBounds());
        Point start = new Point( widgetRect.x + widgetRect.width / 2, 
                widgetRect.y + widgetRect.height + margin );
        Point mid1 = new Point( widgetRect.x - margin, start.y );
        Point mid2 = new Point( mid1.x, widgetRect.y - margin );
        Point end = new Point( start.x, mid2.y );

        List<Point> result = new LinkedList<Point>();
        result.add(start);
        result.add(mid1);
        result.add(mid2);
        result.add(end);

        return result;
    }

}
